package com.gw.quotes.net.service;

import org.ksoap2.serialization.SoapObject;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.gw.quotes.entity.system.Result;
import com.gw.quotes.net.NewException;
import com.gw.quotes.net.Request;
import com.gw.quotes.net.Response;

/**
 * 登陆 verifyuser
 * 
 * @author Administrator
 *
 */
public class UserLoginServiceImpl extends WebBaseServiceImpl {
	
	@Override
	public Response setResponse() {
		return new Response();
	}
	
	@Override
	public void checkParam(Request request) throws NewException {
		if (request == null) {
			throw new NewException(Response.RESULT_ERROR, "传入request不能为空");
		}
		if (checkNull(request.getLoginname())) {
			throw new NewException(Response.RESULT_ERROR, "用户登录名不能为空");
		}
		if (checkNull(request.getPassword())) {
			throw new NewException(Response.RESULT_ERROR, "用户密码不能为空");
		}
	}

	@Override
	public void setParamByRequest(Request request, SoapObject rpc)
			throws NewException {
		// rpc.addProperty("loginname", request.getLoginname());
		// rpc.addProperty("password", request.getPassword());
		rpc.addProperty("arg0", request.getLoginname());
		rpc.addProperty("arg1", request.getPassword());
	}

	@Override
	public String getMethodName() throws NewException {
		return "verifyuser";
	}

	@Override
	public void resolveResponse(Object object, Response response) {
		Gson gson = new Gson();
		java.lang.reflect.Type type = new TypeToken<Result>() {
		}.getType();
		Result result = gson.fromJson(object.toString(), type);
		response.setMsg(result.getMsg());
		response.setResult(result.getResult());
		if (response.getResult() == Response.RESULT_SUCCESS) {
			response.setObj(result.getUser());
			System.out.println(response.toString());
		}
	}


}
